const configBase = require("./webpack.config.base.js");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpackMerge = require("webpack-merge");
const path = require("path");
const webpack = require("webpack");
const api_map = require('./api.config.json')

module.exports = webpackMerge(configBase, {
  entry: "./src/vr3d/js/index.js",
  output: {
    filename: "js/[name].[contenthash:5].js",
    path: path.resolve("src/vr3d/dist"),
  },
  module: {
    rules: [
      {
        test: /\.(jpg|png|gif)/i,
        loader: "url-loader",
        options: {
          limit: 1,
          esMoudel: false,
          name: "[name].[contenthash:5].[ext]",
          outputPath: "images",
        },
      },
    ],
  },
  optimization: {},
  devServer: {
    host: '0.0.0.0',
    port: 80,
    open: true,
    contentBase: path.resolve("src/vr3d/dist"),
    useLocalIp: true,
    proxy:{
      [api_map.test]: {
        target: 'https://api-dev.shulanfd.com',
        changeOrigin: true,
        pathRewrite: {
          [api_map.test]: ''
        }
      }
    },
  },

  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: "src/vr3d/index.html",
      filename: "index.html",
      minify: true
    }),
    new CopyWebpackPlugin({
      patterns: [
        { from: "src/vr3d/images", to: "images" },
        { from: "src/vr3d/css/pano3d.css", to: "css/pano3d.css" },
        { from: "src/vr3d/css/textures/hand.png", to: "css/textures/hand.png" },
        { from: "src/vr3d/js/libs", to: "js/libs" },
      ],
    }),
  ],
});
